package top.tangyh.lamp.care.mapper;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import top.tangyh.basic.base.mapper.SuperMapper;
import top.tangyh.lamp.care.entity.BTimePlan;
import org.springframework.stereotype.Repository;
import top.tangyh.lamp.common.constant.CommonConstant;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * 病人时间计划表
 * </p>
 *
 * @author zqb
 * @date 2024-07-18 15:15:54
 * @create [2024-07-18 15:15:54] [zqb] [代码生成器生成]
 */
@Repository
public interface BTimePlanMapper extends SuperMapper<BTimePlan> {

    default List<BTimePlan> selectListByRangeAndModuleId(String startdate, String endDate, List<String> moduleId, String hospitalNumber) {
        LambdaQueryWrapper<BTimePlan> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(BTimePlan::getModuleId, moduleId)
                .ge(BTimePlan::getTimePoint, startdate)
                .le(BTimePlan::getTimePoint, endDate)
                .eq(BTimePlan::getHospitalNumber,hospitalNumber)
                .eq(BTimePlan::getIsDeleted, 0);
        return this.selectList(queryWrapper);
    }

    default List<BTimePlan> selectListByBusiField(String moduleId,String patientIdent,String hospitalNumber ){
        LambdaQueryWrapper<BTimePlan> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BTimePlan::getModuleId, moduleId)
                .eq(StrUtil.isNotBlank(moduleId),BTimePlan::getModuleId,moduleId)
                .eq(StrUtil.isNotBlank(patientIdent),BTimePlan::getPatientIdent,patientIdent)
                .eq(StrUtil.isNotBlank(hospitalNumber),BTimePlan::getHospitalNumber,hospitalNumber)
                .eq(BTimePlan::getIsDeleted, CommonConstant.NO_NUMBER);
        return this.selectList(queryWrapper);
    }

    default List<BTimePlan> selectByTimeAndPAt(Long time, String patientIdent, String hospitalNumber,String moduleId){
        LambdaQueryWrapper<BTimePlan> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BTimePlan::getModuleId, moduleId)
                .eq(StrUtil.isNotBlank(moduleId),BTimePlan::getModuleId,moduleId)
                .eq(StrUtil.isNotBlank(patientIdent),BTimePlan::getPatientIdent,patientIdent)
                .eq(StrUtil.isNotBlank(hospitalNumber),BTimePlan::getHospitalNumber,hospitalNumber)
                .eq(BTimePlan::getTimePoint, new Date(time));
        return this.selectList(queryWrapper);
    }

    default void deleteByTimeAndPAt(Long time, String patientIdent, String hospitalNumber, String moduleId){
        LambdaQueryWrapper<BTimePlan> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BTimePlan::getModuleId, moduleId)
                .eq(StrUtil.isNotBlank(moduleId),BTimePlan::getModuleId,moduleId)
                .eq(StrUtil.isNotBlank(patientIdent),BTimePlan::getPatientIdent,patientIdent)
                .eq(StrUtil.isNotBlank(hospitalNumber),BTimePlan::getHospitalNumber,hospitalNumber)
                .eq(BTimePlan::getTimePoint, new Date(time));
        delete(queryWrapper);
    }
    
    
}


